package edu.lingnan.house.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.lingnan.house.mapper.HouseMapper;
import edu.lingnan.house.mapper.TbPictureMapper;
import edu.lingnan.house.pojo.TbHouse;
import edu.lingnan.house.pojo.TbPicture;
import edu.lingnan.house.service.HouseService;
import edu.lingnan.house.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HouseServiceImpl extends ServiceImpl<HouseMapper, TbHouse> implements HouseService {
    @Autowired(required = false)
    private HouseMapper houseMapper;
    @Autowired(required = false)
    private TbPictureMapper pictureMapper;

    @Override
    public Result showIndex() {
        List<TbHouse> houses = houseMapper.selectList(null);
        for(int i=0;i<houses.size();i++){
            Integer FangziId = houses.get(i).getId();
            QueryWrapper<TbPicture> picturesQueryWrapper=new QueryWrapper<>();
            picturesQueryWrapper.eq("house_id",FangziId);
            List<TbPicture> pictures=pictureMapper.selectList(picturesQueryWrapper);
            houses.get(i).setTbPictures(pictures);
        }
        return new Result(200,houses,"good");
    }
}
